/* Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 * ===================================================================================================================*/
#include "base/context_builder/op_info.h"
#include <memory>
#include "exe_graph/runtime/tensor.h"
#include "base/context_builder/op_info_impl.h"
#include "common/ge_common/util.h"
#include "graph/debug/ge_util.h"
namespace gert {

OpInfo::OpInfo() : impl_(ge::ComGraphMakeShared<OpInfoImpl>()) {}
OpInfo::~OpInfo() = default;

OpInfo &OpInfo::OpType(const AscendString &op_type) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetOpType(op_type);
  return *this;
}

OpInfo &OpInfo::OpName(const AscendString &op_name) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetOpName(op_name);
  return *this;
}

OpInfo &OpInfo::IONum(size_t input_num, size_t output_num) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetIONum(input_num, output_num);
  return *this;
}

OpInfo &OpInfo::IOInstanceNum(const std::vector<uint32_t> &input_instance_num,
                              const std::vector<uint32_t> &output_instance_num) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetIOInstanceNum(input_instance_num, output_instance_num);
  return *this;
}
OpInfo &OpInfo::SetInputTd(size_t index, ge::DataType dtype, ge::Format origin_format, ge::Format storage_format,
                           const gert::StorageShape &shape) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetInputTd(index, dtype, origin_format, storage_format, shape);
  return *this;
}
OpInfo &OpInfo::SetOutputTd(size_t index, ge::DataType dtype, ge::Format origin_format, ge::Format storage_format,
                            const gert::StorageShape &shape) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetOutputTd(index, dtype, origin_format, storage_format, shape);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, bool attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, int64_t attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, float attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const AscendString &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  std::string tmp(attr.GetString());
  impl_->SetAttr(attr_name, tmp);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const std::vector<bool> &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const std::vector<int64_t> &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const std::vector<float> &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const std::vector<AscendString> &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  std::vector<std::string> tmp;
  for (const auto &item : attr) {
    tmp.emplace_back(item.GetString());
  }
  impl_->SetAttr(attr_name, tmp);
  return *this;
}
OpInfo &OpInfo::Attr(const AscendString &attr_name, const std::vector<std::vector<int64_t>> &attr) {
  GE_CHECK_NOTNULL_EXEC(impl_, return *this);
  impl_->SetAttr(attr_name, attr);
  return *this;
}
}  // namespace gert
